package com.ruoyi.resume.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.resume.domain.model.match.JobMatchVo;
import com.ruoyi.resume.domain.model.match.ResumeMatch;
import com.ruoyi.resume.service.MatchResumeService;
import com.ruoyi.resume.utils.deepseek.DeepSeekClient;
import com.ruoyi.resume.utils.minIO.MinIOUtil;
import io.minio.errors.*;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

@Api("人岗匹配")
@RestController
@RequestMapping("/resume")
public class MatchResumeController {
    @Autowired
    private MatchResumeService matchResumeService;

    @Autowired
    private MinIOUtil minIOUtil;

    @Autowired
    private DeepSeekClient deepSeekClient;

    /**
     * 人岗匹配接口
     * 输入岗位描述，进行简历推荐
     */
    @PostMapping("/match-resume")
    @Anonymous
    public ResponseEntity<?> matchResume(@RequestBody JobMatchVo jobDescription) {
        if(jobDescription.getAlpha() == null){
            jobDescription.setAlpha(0.0);
        }
        if(jobDescription.getWeightType() == null){
            jobDescription.setWeightType("TF-IDF");
        }
        List<ResumeMatch> result = matchResumeService.matchResume(jobDescription);
        return ResponseEntity.ok(result);
    }

    /**
     * 匹配效果可视化
     * */
    @PostMapping("/match-resume-visual")
    @Anonymous
    public ResponseEntity<?> matchResumeVisual(@RequestParam int jobId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        String HTML = matchResumeService.matchResumeVisual(jobId);
        return ResponseEntity.ok(HTML);
    }

}
